<template>
	<z-paging ref="paging" v-model="dataList" @query="query">
		<view class="fixedTop" slot="top">
			<image class="fixedTop_logo"
				src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/19/3dda5f28a3bd47988f1452aa0c99bb4d.png" />
			<view class="fixedTop_couponBg">
				<view>
					<u-text text="商品福利" color="#FFF" size="28rpx" align="center" />
				</view>
				<view class="fixedTop_couponBg_coupon">
					<view class="fixedTop_couponBg_coupon_left">
						<image style="width:80rpx;height: 80rpx ;"
							src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/19/dddb48f6777448a6838eb172b8d533de.png"
							mode="widthFix"></image>
						<view class="fixedTop_couponBg_coupon_left_detail">
							<text class="title">{{couponDetail.favorableTitle}}</text>
							<text class="desc">{{couponDetail.favorableDescription}}</text>
						</view>
					</view>
					<view style="display: flex;align-items: baseline;">
						<text style="font-size: 32rpx;color: #D35549;margin-right: 12rpx;font-weight: bold;">¥</text>
						<u-text size="60rpx" bold :text="couponDetail.favorableFaceValue / 100" color="#D35549" />
					</view>
				</view>

				<view style="margin-top: 32rpx;">
					<u-text text="每天可领取一张，购买时可以对应相应产品现金抵扣" color="#FFF" size="24rpx" align="center" />
				</view>

				<view @click="collectionHandler"
					style="width: 454rpx;height:100rpx; 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.3);border-radius: 100px;margin-top: 52rpx;">
					<u-button type="primary" size="large" shape="circle"
						:text="couponDetail.status?'立即领取':couponDetail.statusText" :disabled="!couponDetail.status"
						:customStyle="customButtonStyle" color="linear-gradient(180deg, #FFDC79 0%, #FEA74F 100%);" />
				</view>
			</view>
			<view style="padding:32rpx 0;box-sizing: border-box;width: 100%;background-color: #FFF;">
				<u-text size="24rpx" color="#AF2853" align="center" text="福利仅限以下商品使用" />
			</view>
		</view>
		<view class="listContainer">
			<view class="listItem" v-for="item in dataList" :key="item.id">
				<u-image :src="item.thumbnail" mode="widthFix" width="200rpx" height="200rpx" />
				<view class="listItem_right">
					<text class="title">{{item.goodsName}}</text>
					<view style="display: flex;align-items: center;">
						<text style="font-size: 24rpx;color: #3D3D3D;">原价：</text>
						<u-text color="#3D3D3D" size="24rpx" :text="item.price/100" mode="price" />
					</view>
					<view style="display: flex;align-items: center;">
						<text style="font-size: 26rpx;color: #FF0000;">福利价：</text>
						<!-- <u-text color="#FF0000" size="26rpx" :text="item.price - couponDetail.favorableFaceValue"
							mode="price" /> -->
						<u-text color="#FF0000" size="26rpx" :text="formatDecimal(
							numSub(
								numDiv(item.price,100), numDiv(couponDetail.favorableFaceValue,100
								)
							)
						)"
							mode="price" />
					</view>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script>
	import {
		favorableGoods,
	} from '@/api/order.js'

	import {
		getCouponDetail,
		checkCouponStatus,
		collectionCoupon,
	} from '@/api/activity.js'
	import {
		formatDecimal
	} from "@/utils/index.js";
	import {
		numSub,
		numDiv,
	} from "@/js_sdk/nl-precisionNum/precisionNum.js";
	export default {
		data() {
			return {
				numSub,
				numDiv,
				formatDecimal:formatDecimal,
				dataList: [],
				id: '',
				couponDetail: {},
				customButtonStyle: {
					height: "100rpx",
					color: "#C60A15",
				}
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		methods: {
			query(pageNum, pageSize) {
				const that = this
				const params = {
					pageSize,
					pageNum,
					favorableId: that.id
				}
				favorableGoods(params).then(res => {
					that.$refs.paging.complete(res.data.rows)
				})

				getCouponDetail(that.id).then(res => {
					const detail = {
						...res.data,
						status: false,
						statusText: ""
					}
					checkCouponStatus(that.id).then(statusResult => {
						detail.statusText = statusResult.data
						if (statusResult.data === '立即领取') {
							detail.status = true
						} else {
							detail.status = false
						}
					})
					that.couponDetail = detail
				})


			},
			async collectionHandler() {
				const result = await collectionCoupon(this.id)
				this.$refs.paging.refresh()
			},
		}
	}
</script>

<style scoped lang="scss">
	.fixedTop {
		width: 694rpx;
		margin: 0 auto;
		margin-top: 26rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		&_logo {
			width: 262rpx;
			height: 88rpx;
		}

		&_couponBg {
			width: 100%;
			height: 554rpx;
			background: linear-gradient(135deg, #FD8054 0%, #FD2D3D 100%);
			border-radius: 20rpx 20rpx 0rpx 0rpx;
			margin-top: 38rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 28rpx;
			box-sizing: border-box;

			&_coupon {
				width: 598rpx;
				height: 162rpx;
				background-image: url("https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/19/602972da4b8c4722959e3b59522bae9f.png");
				background-size: cover;
				background-repeat: no-repeat;
				margin-top: 40rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-left: 40rpx;
				padding-right: 28rpx;

				&_left {
					height: 70rpx;
					display: flex;
					align-items: center;

					&_detail {
						width: 200rpx;
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						margin-left: 20rpx;

						.title {
							font-size: 32rpx;
							color: #D35549;
							font-weight: bold;
							overflow: hidden;
							text-overflow: ellipsis;
							-webkit-box-orient: vertical;
							display: -webkit-box;
							word-break: break-all;
							-webkit-line-clamp: 1;
							line-clamp: 1;
						}

						.desc {
							font-size: 20rpx;
							color: #999999;
							overflow: hidden;
							text-overflow: ellipsis;
							-webkit-box-orient: vertical;
							display: -webkit-box;
							word-break: break-all;
							-webkit-line-clamp: 1;
							line-clamp: 1;
						}
					}
				}
			}
		}
	}

	.listContainer {
		width: 694rpx;
		background-color: #FFF;
		margin: 0 auto;
		border-radius: 0 0 20rpx 20rpx;
		padding: 32rpx 50rpx;
		box-sizing: border-box;

		.listItem {
			width: 100%;
			height: 200rpx;
			display: flex;
			align-items: center;

			&_right {
				flex: 1;
				display: flex;
				flex-direction: column;
				height: 90%;
				justify-content: space-between;
				padding-left: 20rpx;

				.title {
					font-weight: bold;
					font-size: 28rpx;
					color: #3D3D3D;
				}
			}
		}
	}
</style>